{extend name="public/base"/} {block name="body"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
 <!-- <script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
 <script>
   $(function(){
    var geolocation = new qq.maps.Geolocation("QQ6BZ-24HC6-ZAXSZ-MTZAU-5MU2J-HEFEH", "鲜果屋");
     geolocation.getIpLocation(showPosition, showErr)

   })

   function showPosition(position) {
     console.log(1111);
     $.getJSON("{:url('index/cart/changecookie')}", {name: 'positioninit', 'val': position.lat+','+position.lng}, function(json, textStatus) {});
  };
   function showErr() {
     console.log('定位失败');
   };
 </script> -->
 
 <!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" charset="utf-8"></script>
<script>

    wx.config({$wxoptions|json_encode});

    wx.error(function(e){

      	console.log(e);

      });

    wx.getLocation({
    type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
    success: function (res) {
        var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
        var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
        var speed = res.speed; // 速度，以米/每秒计
        var accuracy = res.accuracy; // 位置精度
     //alert(JSON.stringify(res));
     
    
     $.get("http://apis.map.qq.com/ws/geocoder/v1/?location="+latitude+","+longitude+"&key={$mapkey}&get_poi=0&output=jsonp&callback=?",function(data) {
     console.log(data);
     if(data.status==0){
       var province = data.result.address_component.province;
     province = preg_replace('/市/',"",province);
     province = preg_replace('/省/',"",province);
     var city = data.result.address_component.city;
      city = preg_replace('/市/',"",city);
     var qu = data.result.address_component.district;
     $("#address1").val(province+" "+city+" "+qu);
     $("#address2").val(province+" "+city+" "+qu);
     
     }
     
    },'jsonp');   
      
    }
});
</script> -->

<style>
.addresscard-del {
    -ms-flex-preferred-size: 1.306667rem;
    flex-basis: 1.306667rem;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: end;
    -ms-flex-pack: end;
    justify-content: flex-end;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
</style>
<header class="mui-bar mui-bar-nav" style="z-index:7">
    <a class=" mui-icon mui-icon-left-nav mui-pull-left " href="{$backurl}" ></a>
    <h1 class="mui-title">选择地址</h1>
</header>
<div class="mui-content ">
    {volist name="list" id="vo"}
    <div class="addresscard">
        {eq name="$vo['defaults']" value='1'}
        <div class="addresscard-select"><img src="__PUBLIC__/xsd/img/gg.png"></div>{/eq}
        <div class="addresscard-body " data-addressid="{$vo.id}" {eq name="$vo['defaults']" value='1'}data-noc="1"{/eq}>
            <p class="addresscard-title"> <span class="username">{$vo.name}</span> <span class="gender">{eq name="$vo['sex']" value='1'}先生{else /}女士{/eq}</span> <span class="tpl">{$vo.tel}</span> </p>
            <p class="addresscard-address"> <span class="address-tag" style="display: none;"></span> <span class="address-text">{$vo.address}-{$vo.house_number}</span> </p>
        </div>
        <a class="addresscard-edit" href="{:url('index/address/add', array('id'=>$vo['id']))}"> <span class="mui-icon mui-icon-compose"></span></a>
        <a class="addresscard-del" href="javascript:;" data-id="{$vo['id']}"> <span class="mui-icon mui-icon-trash"></span> </a>
    </div>
    {/volist}
    <div class="addressview-bottom">
        <div class="bottom-text" id="addaddress"><span class="mui-icon mui-icon-plus-filled"></span> 新增收货地址</div>
    </div>
</div>
{/block}
{block name="script"}
  <script type="text/javascript">
    $(function(){
      $('#addaddress').on('click',function(){
      	//alert("aa");
        window.location.href = "{:url('index/address/add')}"
      })

      $('.addresscard-body').click(function(){
        var $this = $(this),id = $this.attr('data-addressid'),noc = $this.attr('data-noc');
        if(noc == 1){return ;}

        $.post("{:url('index/address/setDefaults')}", {
            "id": id
        }, function(data) {
            mui.toast('设为默认地址成功！')
            setTimeout(function() {
                //mui.back()
                self.location=document.referrer;
            }, 2000);

        }, "json");
      })

      $('.addresscard-del').on('click', function(){
        var id = $(this).attr('data-id')
        var btnArray = ['否', '是'];
        mui.confirm('您确定要删除地址吗？', '删除地址', btnArray, function(e) {
          if (e.index == 1) {
              $.post("{:url('index/address/del')}", {
                  "id": id
              }, function(data) {
                  mui.toast('删除成功！')
                  setTimeout(function() {
                    location.reload()
                  }, 2000);
              }, "json");

          } else {
            return ;
          }
        })
      })
    })
  </script>  
  
  
  <!-- <script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script> 
  <script>  
   $(function(){    
   	var geolocation = new qq.maps.Geolocation("QQ6BZ-24HC6-ZAXSZ-MTZAU-5MU2J-HEFEH", "鲜果屋");     
   	geolocation.getIpLocation(showPosition, showErr)   })   
   	function showPosition(position) {     console.log(1111);     
   		$.getJSON("{:url('index/cart/changecookie')}", 
   		{name: 'positioninit', 'val': position.lat+','+position.lng}, 
   		function(json, textStatus) {});  };   
   		function showErr() {     console.log('定位失败');   }; 
   </script>
    -->
   
   
{/block}
